package com.ruoyi.base.tool;

import java.util.ArrayList;
import java.util.List;

//自定义协议的数据拼装
public class TypeConverter {

    public static String type10to16v4(String str){

        int num = Integer.parseInt(str);

        return String.format("%04X", num);

    }

    public static String type10to16v2(String str){

        if (str==null){
            return "00";
        }

        int num = Integer.parseInt(str);

        return String.format("%02X", num);

    }

    public static String type16to10(String str){

         return Integer.toString(Integer.parseInt(str, 16));

    }

    public static List<String> value1 (String s){

        ArrayList<String> list = new ArrayList<>();

        String s1 = s.substring(10,26).replaceAll("0","");
        String s2 = TypeConverter.type16to10(s.substring(30,34));

        list.add(s1);
        list.add(s2);

        return list;
    }

    public static String noNull(String s){
        if (s == null) {
            return "0";
        }
        return s;
    }

}
